package com.dlq.emp.action;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dlq.emp.pojo.Emp;
import com.dlq.emp.service.EmpService;
import com.dlq.utils.format.MD5Utils;

@Controller
@RequestMapping("emp")
public class Empaction {

	
	@Autowired
	private EmpService empService;
	
	/**
	 * 登录 验证
	 * @param emp
	 * @param request
	 * @param mm
	 * @return
	 */
	@RequestMapping("empLogin")
	public  String  empLogin(Emp emp,HttpServletRequest request,Model mm){
		System.out.println(emp);
		String md5  = emp.getPwd();
		String md52 = MD5Utils.md5(md5);
		emp.setPwd(md52);
		
		Emp ee = empService.findempLogin(emp);
		if(ee!=null){
			HttpSession session = request.getSession();
			session.setAttribute("empss", ee);
			
			return "/base/index.jsp";
	
		}else{
			mm.addAttribute("msg", "用户不存在或密码错误");
			return "/jsps/login.jsp";
		}
	}
	/**
	 * 
	 * @param id
	 * @param mm
	 * @return
	 */
	@RequestMapping("findempById")
	public  String  findempById(Integer id,Model mm){
		Emp ee  = empService.findempById(id);
		mm.addAttribute("empDd", ee);
		return "/base/index.jsp";
	}

	/**
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("findempByIdlogout")
	public  String  findempByIdlogout(HttpServletRequest request){
		HttpSession session = request.getSession();
		session.removeAttribute("empss");
		return "/jsps/login.jsp";
	}
}
